package com.smooth.site.sx.pc.jifen.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smooth.common.pc.interceptor.PcAccountContext;
import com.smooth.common.site.common.rsp.ReturnResult;
import com.smooth.dao.gen.bean.BizAddress;
import com.smooth.dao.gen.bean.BizStudent;
import com.smooth.site.sx.pc.jifen.service.PcAdressService;
import com.smooth.site.sx.pc.jifen.vo.AddressReq;
import com.smooth.sys.pc.vo.ListRsp;

@Controller
@RequestMapping(value = "/pc")
public class PcAddressController {
	@Autowired
	PcAdressService pcAdressService;
	/**
	 * 学生注册
	 * @param studenRegVo
	 * @param result
	 * @param request
	 * @param response
	 * @return
	 */
	
	@RequestMapping(value = {"c/address/detail"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult detail(@RequestParam(value = "id",required=true)String id, HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizAddress bizAddress = pcAdressService.queryAddressById(id);
		returnResult.setData(bizAddress);
		return returnResult;
	}
	
	

	@RequestMapping(value = {"c/address/list"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult list( HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		String telNo = PcAccountContext.getTelNo();
		ListRsp<BizAddress> blistRsp = pcAdressService.queryAddressByTelNo(telNo);
		returnResult.setData(blistRsp);
		return returnResult;
	}
	
	@RequestMapping(value = {"c/address/save"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult list(@Valid AddressReq addressReq,BindingResult result, HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizStudent bizStudent = (BizStudent) PcAccountContext.getObj(BizStudent.class);
		BizAddress bizAddressRdb = pcAdressService.saveBizAddress(addressReq,bizStudent);
		returnResult.setData(bizAddressRdb);
		return returnResult;
	}
	
	
}
